package com.guigu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.mapper.*;
import com.guigu.pojo.GatherDetailInfo;
import com.guigu.pojo.OrdersParticulars;
import com.guigu.pojo.SupplierSupplyOfGoods;
import com.guigu.service.GatherDetailInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GatherDetailInfoServiceimpl extends ServiceImpl<GatherDetailInfoMapper, GatherDetailInfo> implements GatherDetailInfoService {
    @Autowired
    WarehouseInfoMapper warehouseInfoMapper;//仓库表
    @Autowired
    ShopInfoMapper shopInfoMapper;//商品表
    @Autowired
    SupplierSupplyOfGoodsMapper supplierSupplyOfGoodsMapper;//商品维护表
    @Autowired
    UsersMapper usersMapper;

    @Override
    public Page<GatherDetailInfo> queryAll(GatherDetailInfo gatherDetailInfo, Integer pageno, Integer pagesize) {
        QueryWrapper queryWrapper=
                new QueryWrapper<GatherDetailInfo>();
        //父id(出库表id)
        if (gatherDetailInfo.getGatherId()!=null){
            queryWrapper.eq("gather_id",gatherDetailInfo.getGatherId());
        }
        //仓库id
        if (gatherDetailInfo.getWarId()!=null){
            queryWrapper.eq("war_id",gatherDetailInfo.getWarId());
        }
        //商品维护表id
        if (gatherDetailInfo.getIsDelete()!=null){
            queryWrapper.eq("is_delete",gatherDetailInfo.getSupplyOrderId());
        }
        Page<GatherDetailInfo> page = this.page(new Page<GatherDetailInfo>(pageno, pagesize),queryWrapper);
        for (GatherDetailInfo g : page.getRecords()) {
            //获取仓库表数据
            g.setWarehouseInfo(warehouseInfoMapper.selectById(g.getWarId()));
            //获取商品维护表数据
            SupplierSupplyOfGoods supplierSupplyOfGoods=supplierSupplyOfGoodsMapper.selectById(g.getSupplyOrderId());
            supplierSupplyOfGoods.setShop(shopInfoMapper.selectById(supplierSupplyOfGoods.getGId()));
            g.setSupplierSupplyOfGoods(supplierSupplyOfGoods);
        }
        return page;
    }
    //曹科 入库申请查询的查看详情
    @Override
    public Page<GatherDetailInfo> queryAlldetail(GatherDetailInfo gatherDetailInfo, Integer pageno, Integer pagesize) {
            QueryWrapper queryWrapper=new QueryWrapper();
            queryWrapper.eq("gather_id",gatherDetailInfo.getGatherId());
            queryWrapper.eq("is_delete","0");
            Page<GatherDetailInfo> page=this.page(new Page<GatherDetailInfo>(pageno,pagesize),queryWrapper);
            for (GatherDetailInfo g : page.getRecords()){
                //获取仓库表数据
                g.setWarehouseInfo(warehouseInfoMapper.selectById(g.getWarId()));
                //获取商品维护表数据
                SupplierSupplyOfGoods supplierSupplyOfGoods=supplierSupplyOfGoodsMapper.selectById(g.getSupplyOrderId());
                supplierSupplyOfGoods.setShop(shopInfoMapper.selectById(supplierSupplyOfGoods.getGId()));
                //获取供应商数据
                supplierSupplyOfGoods.setUser(usersMapper.selectById(supplierSupplyOfGoods.getPId()));
                g.setSupplierSupplyOfGoods(supplierSupplyOfGoods);
            }

        return page;
    }
}
